package com.pinda.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageInfo;
import com.pinda.base.entity.PdTruckDriver;
import com.pinda.base.vo.TruckDriverTheTruckMessageVo;
import com.pinda.commonutils.Page;
import com.pinda.feign.TruckDriverFeign;
import com.pinda.service.IPdFleetService;
import com.pinda.service.IPdTruckDriverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 司机表 前端控制器
 * </p>
 *
 * @author lc
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/pd-truck-driver")
public class PdTruckDriverController {

    @Autowired
    TruckDriverFeign truckDriverFeign;


    @Autowired
    IPdFleetService iPdFleetService;

    @Resource
    IPdTruckDriverService iPdTruckDriverService;

    @RequestMapping("/queryPageTruckDriver")
    public PageInfo queryPageTruckDriver(@RequestBody Page page) {
        return this.truckDriverFeign.queryPageTruckDriver(page);
    }


    /**
     * 修改司机的所属车队
     *
     * @param
     * @return
     */
    @RequestMapping("/updateFleetByUserId/{id}/{fleetId}")
    public boolean updateFleetByUserId(@PathVariable("id") String id, @PathVariable("fleetId") String fleetId) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("user_id", id);
        updateWrapper.set("fleet_id", fleetId);
        this.iPdFleetService.updateFleetNumberMinus(id);
        this.iPdFleetService.updateFleetNumberadd(fleetId);
        return this.iPdTruckDriverService.update(updateWrapper);
    }


    @RequestMapping("/queryTruckDriverTheTruckMessage/{id}")
    public TruckDriverTheTruckMessageVo queryTruckDriverTheTruckMessage(@PathVariable("id") String id) {
        return this.truckDriverFeign.queryTruckDriverTheTruckMessage(id);
    }

    @GetMapping("/selectDriver/{userId}")
    public PdTruckDriver selectDriver(@PathVariable("userId") String userId) {
        PdTruckDriver pdTruckDriver = iPdTruckDriverService.selectByUserId(userId);
        return pdTruckDriver;
    }
}



